package com.ciwong.epaper.modules.epaper.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ciwong.epaper.R;

import java.util.ArrayList;
import java.util.List;

public class TeacherDKAdapter extends BaseAdapter {

        private Context mContext;
        private List<String> list = new ArrayList<>();
        private GridView gridView;

        private ImageView tea_dk_child_img;

        private LinearLayout tea_dk_count;

        private TextView tea_dk_count_text2;

        private String videoUri;

        public TeacherDKAdapter(Context mContext,List<String> list,String videoUri){
            this.mContext = mContext;
            this.list = list;
            this.videoUri = videoUri;
        }


        @Override
        public int getCount() {
            if ( "".equals(videoUri) && list.size()>2){
                return 3;
            }else if ( !"".equals(videoUri) && list.size()>2){
                return 2;
            }else {
                return list.size();
            }
        }

        @Override
        public Object getItem(int i) {
            return list.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(final int i, View view, ViewGroup viewGroup){

            if (null == view) {
                view = View.inflate(mContext, R.layout.activity_tea_dk_child, null);
                tea_dk_child_img = (ImageView) view.findViewById(R.id.tea_dk_child_img);
                tea_dk_count = (LinearLayout) view.findViewById(R.id.tea_dk_count);
                tea_dk_count_text2 = (TextView) view.findViewById(R.id.tea_dk_count_text2);
            }
            Glide.with(mContext).load(Uri.parse(list.get(i))).into(tea_dk_child_img);
                int count = list.size();
            if ("".equals(videoUri) && list.size()>2 && i == 2) {
                tea_dk_count_text2.setText(String.valueOf(count));
                tea_dk_count.setVisibility(View.VISIBLE);
            }else if(!"".equals(videoUri) && list.size()>2 && i == 1){
                tea_dk_count_text2.setText(String.valueOf(count));
                tea_dk_count.setVisibility(View.VISIBLE);
            }else {
                tea_dk_count.setVisibility(View.GONE);
            }
       /* DisplayImageOptions options = new DisplayImageOptions.Builder()//
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.RGB_565)//
                .build();
        ImageLoader.getInstance().displayImage(list.get(i),
                user_dk_child_img, options);*/
        /*if (list.size() > 2) {
            user_dk_child_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    imageBrower(i, list);
                }
            });
*/

            return view;

    }
}
